package com.toy.core.security.userdetails;

import com.toy.core.security.GrantedAuthority;
import com.toy.core.security.GrantedAuthorityImpl;

public class UserDetailsImpl implements UserDetail {
	
	private static final long serialVersionUID = -370969693489545491L;
	
	private String username;
	private String password;
	private boolean accountEnabled;
	private boolean accountExpired;
	private boolean accountLocked;
	private boolean credentialsExpired;
	private GrantedAuthority[] authorities;
	
	public UserDetailsImpl(String username,String password,
			boolean accountEnabled, boolean accountExpired,
			boolean accountLocked, boolean credentialsExpired,
			String[] roleCodes) {
		super();
		this.password = password;
		this.username = username;
		this.accountEnabled = accountEnabled;
		this.accountExpired = accountExpired;
		this.accountLocked = accountLocked;
		this.credentialsExpired = credentialsExpired;
		if ( roleCodes != null && roleCodes.length > 0 ){
			authorities = new GrantedAuthorityImpl[roleCodes.length];
			for (int i = 0; i < roleCodes.length; i++) {
				authorities[i] = new GrantedAuthorityImpl(roleCodes[i]);
			}
		}
	}

	public GrantedAuthority[] getAuthorities() {
		return authorities;
	}

	public String getPassword() {
		return password;
	}

	public String getUsername() {
		return username;
	}

	public boolean isAccountEnabled() {
		return accountEnabled;
	}

	public boolean isAccountExpired() {
		return accountExpired;
	}

	public boolean isAccountLocked() {
		return accountLocked;
	}

	public boolean isCredentialsExpired() {
		return credentialsExpired;
	}

}
